<?php

namespace App\Transformers\Page;

use App\Models\Page;
use League\Fractal\TransformerAbstract;

class PagesTransformer extends TransformerAbstract
{
    public function transform(Page $page)
    {
        return [
            'id' => $page->id,
            'user_id' => $page->user_id ?$page->user->name : null,
            'category' => $page->category ? $page->category->title : null,
            'title' => $page->title,
            'views' => $page->views,
            'created_at' => $page->created_at->format('Y-m-d H:i:s'),
            'updated_at' => $page->updated_at->format('Y-m-d H:i:s'),
        ];
    }
}